package javaCode;

/**
 * Created by lxy_920912 on 2017/1/12.
 */
public class LeetCode112 {
       public boolean hasPathSum(TreeNode root, int sum) {

        int nowSum = 0;
        int[] flag = new int[1];
        flag[0] = 0;
        DFSFind(root,sum,nowSum,flag);
        if(flag[0] == 0){
            return false;
        }else{
            return true;
        }
    }
    public void DFSFind(TreeNode root, int target,int nowSum,int[]flag){

        if(root != null){
            if(root.left == null && root.right == null){
                if(target==(root.val+nowSum)){
                    flag[0] =1;
                }
            }
            DFSFind(root.left,target,nowSum+root.val,flag);
            DFSFind(root.right,target,nowSum+root.val,flag);

        }

    }

}
